package spring.framework.context.support;

import spring.framework.beans.BeansException;
import spring.framework.beans.factory.support.DefaultListableBeanFactory;

/**
 * @author fun.pengzh
 * @class spring.framework.context.support.AbstratRefreshableApplicationContext
 * @desc
 * @since 2021-10-07
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {

    private DefaultListableBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() throws BeansException {
        DefaultListableBeanFactory beanFactory = createBeanFactory();
        loadBeanDefinition(beanFactory);
        this.beanFactory = beanFactory;
    }

    private DefaultListableBeanFactory createBeanFactory(){
        return new DefaultListableBeanFactory();
    }

    protected abstract void loadBeanDefinition(DefaultListableBeanFactory beanFactory);

    @Override
    public DefaultListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
